﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;
using System.Text;

/// <summary>
///ZG_SMRZ 的摘要说明
/// </summary>
public partial class ZG_SMRZ
{
    public enum sort { 资格认证 = 1, 资质认证, 实名认证 }
    public static ZG_SMRZ GetByID(int id)
    {

        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            return context.ZG_SMRZ.FirstOrDefault(row => row.ID == id);
        }
    }

    public static List<ZG_SMRZ> GetAll()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            return context.ZG_SMRZ.ToList();
        }
    }

    public void Add()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            context.ZG_SMRZ.InsertOnSubmit(this);
            context.SubmitChanges();
        }
    }

    public void Update()
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            this.GetType().GetMethod("Detach").Invoke(this, null);
            var tbl = context.GetTable<ZG_SMRZ>();
            tbl.Attach(this);
            context.Refresh(RefreshMode.KeepCurrentValues, this);
            context.SubmitChanges();
        }
    }

    public static void Delete(int id)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            var objItem = context.ZG_SMRZ.FirstOrDefault(row => row.ID == id);
            if (objItem == null)
                return;
            context.ZG_SMRZ.DeleteOnSubmit(objItem);
            context.SubmitChanges();
        }
    }

    public static string GetZGSMRZ(object OID)
    {
        using (DataClassesDataContext context = new DataClassesDataContext())
        {
            StringBuilder Return = new StringBuilder();
            object[] pams = { OID.ToString() };
            var query = context.ExecuteQuery<ZG_SMRZ>(@"SELECT Sort FROM dbo.ZG_SMRZB WHERE ID in{0}", pams);
            List<ZG_SMRZ> list = query.ToList();
            for (int i = 0; i < list.Count; i++)
            {
                Return.Append(Enum.GetName(typeof(ZG_SMRZ.sort), list[i].Sort) + ",");
            }
            return Return.ToString();
        }
    }
}